package com.gmrz.uap.config;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * @author Wang Haifeng
 */
public class RequestWrapper extends HttpServletRequestWrapper {

    private final String requestBody;

    public RequestWrapper(HttpServletRequest request) throws IOException {
        super(request);
        StringBuilder stringBuilder = new StringBuilder();
        BufferedReader bufferedReader = request.getReader();
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            stringBuilder.append(line);
        }
        requestBody = stringBuilder.toString();
    }

    public String getRequestPayload() {
        return requestBody;
    }
}